<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆日志</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../css/homepage/loginLog.css" media="all"/>

</head>
<body>
    <div class="vessel-body">
        <table id="log_table" lay-filter="log_table"></table>
    </div>
</body>
<script src="../../layui/layui.js"></script>
<script>
    layui.use(['table'],function (){
        var $ = layui.$,
            table = layui.table;

        var logtable = table.render({
            elem:'#log_table',
            url:'/homepage/getLoginLog',
            page:true,
            limits:[10,20,30],
            height:400,
            cols:[
                [
                    {field:'',title:'序号',fixed:'left',width:80,align:'center',templet:function (d){
                        return d.LAY_INDEX
                        }},
                    {field:'userJobNumber',title:'工号',},
                    {field:'userAccount',title:'账号',},
                    {field:'loginIp',title:'ip地址',},
                    {field:'loginTime',title:'登录时间',width: 200},
                    {field:'state',title:'登录状态',templet(d){
                            if(d.state == 1){
                                return `<span style="color: #3aa83a">成功</span>`
                            }else{
                                return `<span style="color: #de0303">失败</span>`
                            }
                        }},
                    {field: '',title:'操作',toolbar:'#tool'}
                ]
            ],
            toolbar:true,
            parseData:function (res){
                console.log(res)
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
        })

        table.on('tool(log_table)',function (obj){
            console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('确认删除该条日志吗？',function (){
                    console.log('确认')
                    $.get({
                        url:'/homepage/delLoginLog',
                        data:{id:obj.data.id},
                        dataType:'json',
                        success:res=>{
                            if(res.state == '200'){
                                layer.msg('删除成功')
                                logtable.reload()
                            }else{
                                layer.msg('删除失败')
                            }
                        }
                    })
                })
            }
        })
    })
</script>
<script type="text/html" id="tool">
    <span style="color: #de0303" lay-event="del">删除</span>
</script>
</html>